package GUI.UI;

import GUI.component.BackGroundPanel;
import GUI.util.PathUtils;
import GUI.util.ScreenUtils;
import Operation.Login;
import Operation.jdbc;
import User.administrators;
import User.commonuser;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;

public class GUI_REGISTER {
    JFrame jf = new JFrame("足球管理系统注册");

    final int WIDTH = 1280;
    final int HEIGHT = 720;

    public void init() throws Exception {
        //设置窗口相关属性
        jf.setBounds((ScreenUtils.getScreenWidth() - WIDTH) / 2, (ScreenUtils.getScreenHeight() - HEIGHT) / 2, WIDTH, HEIGHT);//设置坐标和大小
        jf.setBounds(0, 0, ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight());//设置坐标和大小
        jf.setUndecorated(true);//设置边框不可见
        jf.setResizable(false);//大小不可变
        //设置窗口内容
        //设置背景图片

        BackGroundPanel bgPanel = new BackGroundPanel(ImageIO.read(new File(PathUtils.getRealPath("REGISTER.png"))));
        //组装登陆相关元素
        Box vBox = Box.createVerticalBox();
        //组装用户名
        Box uBox = Box.createHorizontalBox();
        JLabel uLabel = new JLabel("用 户 名 :");
        uLabel.setFont(new Font("黑体", Font.PLAIN, ScreenUtils.getScreenWidth() / 60));//设置字体，风格，大小
        uLabel.setForeground(Color.WHITE);//设置文字颜色
        JTextField uField = new JTextField(ScreenUtils.getScreenWidth() / 70);

        uBox.add(uLabel);
        uBox.add(Box.createHorizontalStrut(ScreenUtils.getScreenWidth() / 100));
        uBox.add(uField);
        //组装密码
        Box pBox = Box.createHorizontalBox();
        JLabel pLabel = new JLabel("密    码 :");
        pLabel.setFont(new Font("黑体", Font.PLAIN, ScreenUtils.getScreenWidth() / 60));
        pLabel.setForeground(Color.WHITE);
        JTextField pField = new JTextField(ScreenUtils.getScreenWidth() / 70);


        pBox.add(pLabel);
        pBox.add(Box.createHorizontalStrut(ScreenUtils.getScreenWidth() / 100));
        pBox.add(pField);
        //组装重新输入密码
        Box nBox = Box.createHorizontalBox();
        JLabel nLabel = new JLabel("重新输入密码:");
        nLabel.setFont(new Font("黑体", Font.PLAIN, ScreenUtils.getScreenWidth() / 60));
        nLabel.setForeground(Color.WHITE);
        JTextField nField = new JTextField(ScreenUtils.getScreenWidth() / 70);


        nBox.add(nLabel);
        nBox.add(Box.createHorizontalStrut(ScreenUtils.getScreenWidth() / 100));
        nBox.add(nField);

        //组装按钮
        Box btnBox = Box.createHorizontalBox();
        JButton registBtn = new JButton("注册");
//        registBtn.setPreferredSize(new Dimension(ScreenUtils.getScreenWidth()/20, ScreenUtils.getScreenHeight()/10));
        registBtn.setFont(new Font("黑体", Font.PLAIN, ScreenUtils.getScreenWidth() / 60));
        JButton backBtn = new JButton("返回登录界面");
//        loginBtn.setPreferredSize(new Dimension(ScreenUtils.getScreenWidth()/20, ScreenUtils.getScreenHeight()/10));
        backBtn.setFont(new Font("黑体", Font.PLAIN, ScreenUtils.getScreenWidth() / 60));

        btnBox.add(registBtn);
        btnBox.add(Box.createHorizontalStrut(ScreenUtils.getScreenWidth() / 20));
        btnBox.add(backBtn);
        btnBox.add(Box.createHorizontalStrut(ScreenUtils.getScreenWidth() / 20));
        vBox.add(Box.createVerticalStrut((int) (ScreenUtils.getScreenHeight() / 3)));
        vBox.add(uBox);
        vBox.add(Box.createVerticalStrut(ScreenUtils.getScreenHeight() / 20));
        vBox.add(pBox);
        vBox.add(Box.createVerticalStrut(ScreenUtils.getScreenHeight() / 20));
        vBox.add(nBox);
        vBox.add(Box.createVerticalStrut(ScreenUtils.getScreenHeight() / 20));
        vBox.add(btnBox);

        bgPanel.add(Box.createHorizontalStrut((int) (ScreenUtils.getScreenWidth() / 3)));
        bgPanel.add(vBox);
        jf.add(bgPanel);


        jf.setVisible(true);

        registBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //获取用户信息
                String username = uField.getText().trim();
                String password = pField.getText().trim();
                //访问后台接口4‘；
            }
        });

        backBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //跳转到登录页面
                try {
                    new GUI_LOGIN().init();
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }
                //当前界面消失
                jf.dispose();
            }
        });
    }

        public static void main(String[] args){
            try {
                new GUI_REGISTER().init();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

    }
